/**
 * 
 */
package cn.biplam.front.template.control;

import java.util.ArrayList;

import cn.biplam.common.tools.TOOLS;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.KvMap;
import cn.biplam.front.component.data.tree.TreeData;
import cn.biplam.front.html.HtmlDiv;
import cn.biplam.front.html.HtmlImage;
import cn.biplam.front.html.HtmlValue;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.html.base.Const.Clear_Type;
import cn.biplam.front.html.base.Const.Float_Type;
import cn.biplam.front.html.base.Const.Position_Mode;
import cn.biplam.front.html.base.Const.Visibility_Mode;
import cn.biplam.front.html.base.Const.Window_Event;
import cn.biplam.front.template.base.CheckBox;
import cn.biplam.front.template.base.Text;
import cn.biplam.front.template.callback.TreeCallBack;
import cn.biplam.front.template.control.tree.Icon;
import cn.biplam.front.template.control.tree.PreImageOld;

/**
 * 树形控件模板
 * @author 	WangSong 2009-4-11 上午11:08:30
 * @version 1.0
 */
public class Tree {

	/**树的容器 */
	private HtmlWindow tree;
	/**树的id */
	private String sID;
	/**行为id */
	private String actionId;
	/**父容器id，用来保证树的唯一 */
	private String pcid;
	/**主目录路径 */
	private String sHomeUrl;
	/**treeData容器 */
	private ArrayList<Object[]> alTreeData;
	/**树的操作类 */
	private TreeData treeData;
	/**是否显示复选框 */
	private boolean showCheckBox = false;
	/**是否显示右键菜单 */
	private boolean showRightMenu = false;
	/**右键菜单项 */
	private ArrayList<HtmlWindow> rightMenu;
	/**节点与右键菜单的映射关系 */
	private KvMap<Integer,String[]> nodeRightMapping;
	/**节点与右键菜单的映射关系计数器 */
	private int iCount=0;
	/**当前节点是否是跟节点 */
	private boolean isRoot = false;
	/**算出树的节点最大长度 */
	private int maxLength;
	/**回调 */
	private TreeCallBack mTreeCallBack;
	/**向下取几级节点信息 */
	private int levelDown;
	/**虚根计数器 */
	private int vrCount;
	/**节点类型 */
	private String nodeType;
	/**展开的节点id */
	private String extendNodeId;
	/**展开的节点id的父亲们 */
	private KvMap<String,String> extentNodeParents;
	/**根节点的父亲，树刷新时使用 */
	private String rootParent;
	/**是否显示加号减号 */
	private boolean showPicExtend = true;
	/**onMouseOver是否已经设置 */
	private boolean onMouseOverIsSet = false;
	/**当前节点容器ID */
	@SuppressWarnings("unused")
	private String nodeContainerId;
	/**自定义参数 */
	private String customerParam;
	/**是否进行operator过滤*/
	private String isFilterByOperator;
	/** 展开节点点击*/
	private boolean extendClick;
	/** 记录treeData不为空的数目*/
	private int treeDataCount;
	/** 单棵树是否显示虚根 true:显示 false:不显示  默认:false*/
	private boolean showVirRoot = false;
	/** 过滤数据操作id*/
	private String filterOperatorId;


	public Tree(String pcid,String actionId,ArrayList<Object[]> alTreeData,String sHomeUrl){
		this.pcid = pcid;
		this.tree=new HtmlDiv(pcid+actionId+",-1","tree");
		this.actionId=actionId;
		this.sHomeUrl=sHomeUrl;
		this.alTreeData = alTreeData;
		this.rightMenu = new ArrayList<HtmlWindow>();
		this.nodeRightMapping = new KvMap<Integer,String[]>();
	}
	
	/**
	 * 设置是否显示复选框
	 * @param showCheckBox true显示
	 */
	public void setCheckBox(boolean showCheckBox){
		this.showCheckBox = showCheckBox;
	}
	
	/**
	 * 设置树的右键菜单
	 * @param rightMenu  右键菜单
	 * @param objectType  当前右键菜单对应的树的节点类型,不设置类型的节点不显示右键菜单
	 * @throws ErrorMessage 
	 */
	public void _setRightMenu(HtmlWindow rightMenu,String ... objectType) throws ErrorMessage{
		if(!this.showRightMenu){
			this.showRightMenu = true;
		}
		this.rightMenu.add(rightMenu);
		for(int i=0;i<objectType.length;i++){
			this.nodeRightMapping.put(iCount,new String[]{objectType[i],rightMenu.getID()});
			this.iCount++;
		}
	}
	
	/**
	 * 设置展开节点的Id
	 * @param extendNodeId 节点id
	 */
	public void setExtendNodeId(String extendNodeId) {
		setExtendNodeId(extendNodeId, false);
	}
	
	/**
	 * 设置展开节点的Id
	 * @param extendNodeId
	 * @param click 是否点击  true:点击  false:不点击，只标识背景颜色
	 */
	public void setExtendNodeId(String extendNodeId,boolean click) {
		this.extendNodeId = extendNodeId;
		this.extendClick = click;
	}
	
	/**
	 * 是否显示加号减号
	 * @param showPicExtend
	 */
	public void showPicExtend(boolean showPicExtend){
		this.showPicExtend = showPicExtend;
	}
	
	/**
	 * 设置树的当前节点容器id
	 * @param nodeContainerId
	 */
	public void setNodeContainerId(String nodeContainerId){
		this.nodeContainerId = nodeContainerId;
	}
	
	/**
	 * 设置树的自定义参数
	 * @param customerParam
	 */
	public void setCustomerParam(String customerParam){
		this.customerParam = customerParam;
	}
	
	/**
	 * 是否根据operator过滤
	 * @param isFilterByOperator
	 */
	public void setFilterByOperator(String isFilterByOperator){
		this.isFilterByOperator = isFilterByOperator;
	}
	
	/**
	 * 设置是否显示整棵树的虚根,不为空则显示,为空则不显示
	 * @param treeVirRootName
	 */
	public void setShowVirRoot(boolean showVirRoot){
		this.showVirRoot = showVirRoot;
	}
	
	/**
	 * 设置索引树过滤操作id
	 * @param filterOperatorId 过滤操作id
	 */
	public void setFilterOperatorId(String filterOperatorId) {
		this.filterOperatorId = filterOperatorId;
	}

	/**
	 * 取树
	 * @return HtmlDiv
	 * @throws ErrorMessage
	 */
	public HtmlWindow get() throws ErrorMessage{
		//循环alTreeData，判断alTreeData大小是否大于1，大于1则设置虚根，否则直接调用generate(HtmlDiv tree)生成树
		/**设置虚根，
		   判断虚根是否设置，没设置，抛出异常
		   虚根的页面结构为虚根和虚根的子，在虚根的子中调用generate(HtmlDiv tree)，虚根div的ID为cid+order */
		int alSize = this.alTreeData.size();
		for(int i=0;i<alSize;i++){
			this.treeData = (TreeData)this.alTreeData.get(i)[0];
			this.mTreeCallBack = (TreeCallBack)this.alTreeData.get(i)[1];
			isTreeDatasNull();
			this.levelDown = this.treeData.getLevelDown();
			//设置展开节点信息
			this.getExtendNodeParent();
			if(alSize>1 || showVirRoot){//设置虚根
				this.setVroot();
			}else{
				this.generate(tree);
			}
			//绑定左键容器id，左键目标id、是否显示右键、是否显示checkBox等信息
			if(this.isRoot){
				tree.put(new HtmlValue(pcid+actionId+nodeType,
						                    mTreeCallBack.getLeftClickTargetId()+","+
						                    mTreeCallBack.getLeftClickActionId()+","+
						                    showRightMenu+","+
						                    showCheckBox+","+
						                    rootParent+","+
						                    mTreeCallBack.getBusinessType()+","+
						                    TOOLS.intToString(treeData.getLevelDown())+","+
						                    null+","+
						                    null+","+
						                    null+","+
						                    filterOperatorId));
			}
		}
		/**设置整个树的参数*/
		setWholeTreeParam();
		//设置右键菜单
		if(this.showRightMenu && this.isRoot){
			this._putRightMenu();
			tree.put(new HtmlValue(pcid+actionId+"nodehi",sID+"nodehi",""));
			tree.put(new HtmlValue(pcid+actionId+"level",sID+"level",""));
		}
		return tree;
	}
	
	/**
	 * 返回树的节点的最大长度
	 * @return int
	 */
	public int getNodeMaxLength(){
		return this.maxLength;
	}
	
	/**
	 * 判断是否为空
	 */
	private void isTreeDatasNull(){
		if(!treeData.haveNext()){
			treeDataCount++;
		}
	}
	
	/**
	 * 设置整颗树的参数
	 * @throws ErrorMessage
	 */
	private void setWholeTreeParam() throws ErrorMessage{
		if(treeDataCount == alTreeData.size()){
			isRoot = true;
		}
		if(isRoot){
			/**展开节点的id*/
			tree.put(new HtmlValue(pcid+actionId+"etId",
					                    extendNodeId));
			/**树的自定义参数*/
			tree.put(new HtmlValue(pcid+actionId+"cuPam",
					                    customerParam));
			tree.put(new HtmlValue(pcid+actionId+"isFiByOpId",
					                    isFilterByOperator));
			String showVr = "N";
			/**整棵树的虚根,刷新的时候需要传此参数*/
			if(showVirRoot){
				showVr = "Y";
			}
			tree.put(new HtmlValue(pcid+actionId+"vN",
					showVr));
		}
	}

	/**
	 * 向传入的容器里放入树节点
	 * @param tree	父容器
	 * @throws ErrorMessage 
	 */
	private void generate(HtmlWindow tree) throws ErrorMessage{

		String dID = "";
		/**绘制结点
		 * 	1.if(haveNext()) 移动游标 ，绘制结点（三个容器）*/
		if(treeData.haveNext()){
			treeData.moveNext();
			if(this.treeData.isRoot()){
				this.isRoot = true;
				this.rootParent = this.treeData.getNodeParent();
			}
			//绑定需要展开的节点的脚本
			this.bindExtendNodeJs();
			this.onMouseOverIsSet = false;
			
			char haveLBrother = treeData.haveLBrother();
			this.nodeType = this.treeData.getNodeType();
			dID = this.getPicId();
			/**当前节点的整体容器,放当前节点和当前节点的子节点*/
			HtmlDiv nodes = new HtmlDiv(dID);
			/**当前节点*/
			HtmlDiv currentNode = this._getNode(dID+",ct");
			/**设置节点大小，不然可能会出现换行*/
			String nodeshow = null;
			if(treeData.getNodeName()!=null && !"".equals(treeData.getNodeName().trim())){
				nodeshow = treeData.getNodeName();
			}else{
				nodeshow = treeData.getNodeId();
			}
			currentNode.setStyleWidth(TOOLS.intToString(_getNodeLength(nodeshow)));
			nodes.put(currentNode);
			/**判断是否有儿子
			 * 	如果有儿子,递归(自己的儿子容器)
			 * 判断是否有弟弟
			 * 		如果有弟弟 递归(自己的容器)
			 */
			HtmlDiv childSet = new HtmlDiv(dID+",cset","urs");
			/**所有儿子容器都预置为hidden和绝对定位，这样就不会在客户端存在占位，从而导致出现空白行*/
			/**另：与占位有关的这两个属性，似乎必须在服务器端通过标签传过去，否则Ajx刷新后仍然有占位*/
			if(this.treeData.getNodeLevel()>=this.levelDown){
				childSet.setStyle("display", "none");
			}
			if('1' == this.treeData.haveChild() && this.treeData.getNodeLevel()<this.levelDown){
				/**当前节点的子节点集合*/
				generate(childSet);
			}
			nodes.put(childSet);
			tree.put(nodes);
			if('1' == haveLBrother){
				this.generate(tree);
			}
		}
	}

	/**
	 * 生成树的当前结点
	 * @return HtmlDiv
	 * @throws ErrorMessage
	 */
	private HtmlDiv _getNode(String id) throws ErrorMessage{

		/**树的当前节点*/
		HtmlDiv node;
		node=new HtmlDiv(id,"uvr");

		HtmlDiv[] aDiv=this._createPreImage(
				this.getPicId(), 
				sHomeUrl,
				treeData.getNodeId(),
				treeData.getNodeLevel(),
				treeData.haveBrother(),
				treeData.haveLBrother(),
				treeData.isLeaf(),
				treeData.getParentSibling());
		for(HtmlDiv ite:aDiv){
			node.put(ite);
		}
		if(this.showCheckBox){
			node.put(this._getCheckBoxDiv(this.sID+","+treeData.getNodeId()));
		}
		node.put(this._getNodePic());
		if(treeData.getNodeName()!=null && !"".equals(treeData.getNodeName().trim())){
			node.put(_createTreeText(treeData.getNodeName()));
		}else{
			node.put(_createTreeText(treeData.getNodeId()));
		}

		return node;
	}

	/**
	 * 取树的图片信息
	 * @param sID  树id
	 * @param sHomeUrl 项目的主目录
	 * @param sNodeID  节点id
	 * @param iLevel   节点级别
	 * @param cHasGG  是否有哥哥
	 * @param cHasDD  是否有弟弟
	 * @param cHasChild  是否有儿子
	 * @param aParentHasDD  父亲是否有弟弟
	 * @return  HtmlDiv[]
	 * @throws ErrorMessage
	 */
	private HtmlDiv[] _createPreImage(String sID,String sHomeUrl,String sNodeID,int iLevel,
			char cHasGG,char cHasDD,char cHasChild,char[] aParentHasDD) throws ErrorMessage{
		HtmlDiv[] aDiv=new PreImageOld(sID, sHomeUrl, sNodeID, iLevel, 
				cHasGG, cHasDD, cHasChild, aParentHasDD,this.levelDown,showPicExtend).getAll();
		return aDiv;
	}

	/**
	 * 取树的节点说明信息
	 * @param text  树的说明信息
	 * @return HtmlWindow
	 * @throws ErrorMessage
	 */
	private HtmlWindow _createTreeText(String text) throws ErrorMessage{
		/**拼接树的节点说明的id,目前以tree_id,node_id的方式拼接*/
		HtmlWindow mText = new Text(text,this.getPicId()+"text").get();
		mText.setCssID("n");
		/**右键菜单的设置，根据节点的类别设置*/
		this.bindRightMenu(mText);
		/**树的左键*/	
		this.bindLeftOnclick(mText);
		/**加隐藏表单，用于右键treeS ajx的pr()和左键ajx的p()*/
		mText.put(new HtmlValue(this.getPicId()+"text"+"r",
				                this.treeData.getNodeId()+","+
				                this.treeData.getNodeRealId()+","+
				                this.treeData.getNodeLevel()+","+
				                this.treeData.getNodeType()));
		this._getNodeLength(text);
		return mText;
	}

	/**
	 * 取数的复选框信息
	 * @param divId  复选框id
	 * @return HtmlDiv
	 * @throws ErrorMessage
	 */
	private HtmlDiv _getCheckBoxDiv(String divId) throws ErrorMessage{
		HtmlDiv mDiv = new CheckBox(this.sID+"ckb",divId,this.sHomeUrl).get();
		return mDiv;
	}

	/**
	 * 将右键菜单放入tree的容器中
	 * @throws ErrorMessage 
	 */
	private void _putRightMenu() throws ErrorMessage{
		for(int i=0;i<this.rightMenu.size();i++){
			tree.put(this.rightMenu.get(i));
		}
		this._generateRightMenuJsData();

	}

	/**
	 * 动态生成右键菜单的js需要的input数据
	 * @throws ErrorMessage 
	 */
	private void _generateRightMenuJsData() throws ErrorMessage{
		for(int i=0;i<this.nodeRightMapping.size();i++){
			this.tree.put(new HtmlValue(this.pcid+this.actionId+nodeRightMapping.getByKey(i)[0],
					this.pcid+this.actionId+nodeRightMapping.getByKey(i)[0],
					nodeRightMapping.getByKey(i)[1]));
		}
	}

	/**
	 * 设置树的节点的长度
	 * @throws ErrorMessage 
	 */
	private int _getNodeLength(String text) throws ErrorMessage{
		int base=this.treeData.getNodeLevel()+1;
		if(this.showCheckBox){
			base = base+1;
		}
		int length = 18*base+TOOLS.getTextLength(text)+text.length();
		if(length>this.maxLength){
			this.maxLength=length;
		}
		return length;
	}

	/**
	 * 设置图标
	 * @throws ErrorMessage 
	 */
	private HtmlWindow _getNodePic() throws ErrorMessage{

		//取图片的名字
		String picName = this.mTreeCallBack.getNodePic(this.treeData.getOperatorType(),
				this.isLeaf());
		//取图片显示页面
		Icon mIcon = new Icon(this.sHomeUrl,picName,this.treeData.getNodeLevel(),this.levelDown);
		return mIcon.get(this.getPicId(), this.treeData.isLeaf(), this.treeData.isRoot());
	}

	/**
	 * 设置树的虚根
	 * @throws ErrorMessage
	 */
	private void setVroot() throws ErrorMessage{
		if(this.treeData.getVNodeName()==null || "".equals(this.treeData.getVNodeName().trim())){
			//throw new ErrorMessage("请设置树的虚根:"+this.treeData.getNodeName());
			generate(tree);
		}else{
			String vrID = this.actionId+","+this.vrCount;
			//虚根整体的Div
			HtmlWindow vr = new HtmlDiv(vrID);
			vr.setClear(Clear_Type.Both);
			//虚根显示的Div
			HtmlWindow vrNode = new HtmlDiv(vrID+",ct");
			this.setVrootNode(vrNode,vrID+",ct");
			vrNode.setStyle("cursor", "hand");
			//虚根儿子的Div
			HtmlWindow vrChild = new HtmlDiv(vrID+",cset");
			this.generate(vrChild);
//			vrChild.setVisibility(Visibility_Mode.Hidden);
//			vrChild.setPositionMode(Position_Mode.Absolute);
			vrChild.setVisibility(Visibility_Mode.Inherit);
			vrChild.setStyle("position", "static");
			vrChild.setMarginLeft("18");
	
			vrNode.bind(Window_Event.OnClick,"vrp('"+vrID+"')");
			//vrNode.bind("vrp('"+vrID+"');");
			vr.put(vrNode);
			vr.put(vrChild);
	
	
			tree.put(vr);
			this.vrCount++;
		}
	}

	/**
	 * 虚根设置信息
	 * @param vrNode
	 * @throws ErrorMessage 
	 */
	private void setVrootNode(HtmlWindow vrNode,String vnId) throws ErrorMessage{
		HtmlWindow pic = new HtmlDiv();
		pic.setFloat(Float_Type.Left);
		pic.setStyleWidth("18");
		pic.setStyleHeight("18");
		this.getVrPic(pic,vnId);
		vrNode.put(pic);
		HtmlWindow vrText = new Text(this.treeData.getVNodeName()).get();
		vrNode.put(vrText);
	}

	/**
	 * 获取图片显示页面
	 * @param ReportID
	 * @param isLeaf
	 * @param isRoot
	 * @throws ErrorMessage
	 */
	private void getVrPic(HtmlWindow pic,String vrPicID) throws ErrorMessage{
		HtmlWindow open = this._getIcon(vrPicID+"s",this.sHomeUrl+"/images/minus5.gif");
		HtmlWindow uopen = this._getIcon(vrPicID+"u",this.sHomeUrl+"/images/plus5.gif");
		uopen.setVisibility(Visibility_Mode.Hidden);
		pic.put(uopen);
		pic.put(open);
	}

	/**
	 * 创建一个用于图片切换的内置Div
	 */
	private HtmlWindow _getIcon(String ID,String imageUrl) throws ErrorMessage{
		HtmlWindow div = new HtmlDiv(ID);
		div.setPositionMode(Position_Mode.Absolute);
		HtmlWindow mImage=new HtmlImage(imageUrl,"tinorm");
		div.put(mImage);
		return div;
	}

	/**
	 * 树的右键绑定
	 * @param mText
	 * @throws ErrorMessage
	 */
	private void bindRightMenu(HtmlWindow mText) throws ErrorMessage{
		String rightKey =this.treeData.getNodeType()+this.treeData.getOperatorType();
		if(this.showRightMenu){
			mText.bind(Window_Event.OnContextMenu,"showRM(this,'"+rightKey+"'); return false;");
			this._bindTextOnMouseOver(mText);
		}
	}

	/**
	 * 树的左键脚本绑定
	 * @param mText
	 * @throws ErrorMessage 
	 */
	private void bindLeftOnclick(HtmlWindow mText) throws ErrorMessage{
		//取绑定脚本
		String leftScript = this.mTreeCallBack.getLeftClickScript(this.treeData.getOperatorType(),
				this.isLeaf(), 
				this.getTreeId(), 
				this.treeData.getNodeLevel(), 
				this.levelDown);
		if(TOOLS.StringIsEmpty(mText.getID())){
			throw new ErrorMessage("oldTree Error,Tree Text ContainorId is null:"+
					"".equals(mText.getID())+","+
					"null".equals(mText.getID())+","+
							(mText.getID()==null));
		}
		if(leftScript!=null && !"".equals(leftScript)){
			mText.bind(Window_Event.OnClick,leftScript);
			this._bindTextOnMouseOver(mText);
		}
	}
	
	/**
	 * 设置onMouseOver
	 * @param mText
	 * @throws ErrorMessage
	 */
	private void _bindTextOnMouseOver(HtmlWindow mText) throws ErrorMessage{
		if(!this.onMouseOverIsSet){
			mText.bind(Window_Event.OnmouseOver,"onNode(this)");
			this.onMouseOverIsSet = true;
		}
	}

	/**
	 * 判断是否是叶子节点
	 * @return boolean
	 * @throws ErrorMessage
	 */
	private boolean isLeaf() throws ErrorMessage{
		boolean isLeaf = false;
		if(this.treeData.isLeaf()=='0'){
			isLeaf = true;
		}
		return isLeaf;
	}

	/**
	 * 拼接树的节点ID：pcid+actionid,nodeId,nodeType,operatorType,nodeLevel,是否有哥哥,是否有弟弟,realId,父亲们是否有弟弟
	 * @return 树的ID
	 * @throws ErrorMessage 
	 */
	private String getTreeId() throws ErrorMessage{
		return this.getPicId();
	}

	/**
	 * 拼接树节点图片的ID：pcid+actionid,nodeId,nodeType,operatorType,nodeLevel,是否有哥哥,是否有弟弟,realId,父亲们是否有弟弟
	 * @return 图片ID
	 * @throws ErrorMessage
	 */
	private String getPicId() throws ErrorMessage{
		StringBuilder sb = new StringBuilder();

		sb.append(this.pcid+this.actionId+",");
		sb.append(this.treeData.getNodeId()+",");
		sb.append(this.treeData.getNodeType()+",");
		sb.append(this.treeData.getOperatorType()+",");
		sb.append(this.treeData.getNodeLevel()+",");
		sb.append(this.treeData.haveBrother()+",");
		sb.append(this.treeData.haveLBrother()+",");
		sb.append(this.treeData.getNodeRealId()+",");
		sb.append(this.getParentsHaveLBrother());
		
		return sb.toString();
	}

	/**
	 * 取父亲们是否有弟弟
	 * @return 字符串，以"_"分割
	 */
	private String getParentsHaveLBrother(){
		String parentsHaveLBrother = "";
		char[] c = this.treeData.getParentSibling();
		for(int i=0;i<c.length;i++){
			if(i==0){
				parentsHaveLBrother = String.valueOf(c[i]);
			}else{
				if(String.valueOf(c[i])!=null){
					parentsHaveLBrother = parentsHaveLBrother +"_"+String.valueOf(c[i]);
				}
			}
		}
		return parentsHaveLBrother;
	}
	
	/**
	 * 初始化需要展开节点的父亲们
	 * @throws ErrorMessage 
	 */
	private void getExtendNodeParent() throws ErrorMessage{
		if(this.extendNodeId!=null && 
				 !"".equals(this.extendNodeId) && 
				 this.extentNodeParents==null){
			this.extentNodeParents = this.treeData.getExtendNodeAllParent(extendNodeId);
			this.tree.bind("$('"+pcid+actionId+"etId').value='"+extendNodeId+"';");
		}
	}
	
	/**
	 * 设置树的某一节点展开脚本绑定
	 * @throws ErrorMessage 
	 */
	private void bindExtendNodeJs() throws ErrorMessage{
		//如果设置了需要展开的节点id，则判断当前节点是否是 需展开的节点的父亲之一，是则绑定脚本。
		if(this.extentNodeParents!=null && 
				this.extentNodeParents.getByKey(this.treeData.getNodeId())!=null){
			this.tree.bind("tk('"+this.getPicId()+",c','"+this.pcid+this.actionId+"');");
		}
		if(treeData.getNodeId().equals(extendNodeId)){
			if(extendClick){
				tree.bind("$('"+getPicId()+"text').click();");
			}else{
				tree.bind("changeBg($('"+getPicId()+"text'));");
			}
		}
	}
	
	/**
	 * 树的节点索引id
	 */
	public enum TreeID_Index{
		/** 节点id */
		NodeID (1),
		/** 节点类型 */
		NodeType (2),
		/** 节点操作类型 */
		OperatorType (3),
		/** 节点级别 */
		NodeLevel (4),
		/** 是否有哥哥 */
		HaveBrother (5),
		/** 是否有弟弟*/
		HaveLBrother(6),
		/** 真实id*/
		NodeRealId(7),
		/** 父亲是否有弟弟*/
		ParentsHaveLBrother(8);
		private int value;
		private TreeID_Index(int value){this.value=value;}
		public int toInt() {return value;}
	}

}
